const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showIcon:true,
    bannerList: [],
    needList: [],
    supplyList: [],
    produceList: [],
    typeList: [],
  },

  clickRedirect:function(e){
    wx.redirectTo({
      url: '../form/form'
    })
  },
  
  handleInputChange(e){
    let value = e.detail.value;
    if( value ){
      this.setData({showIcon:false});
    }
  },
// 获取banner列表
  getBannerList(num = 3){
    let that=this
    app.login().then(function(_token){
      wx.request({
        url: app.baseApiUrl + 'banners',
        data:{limit:num},
        header:{'token': _token},
        success (response){
          that.setData({bannerList:response.data.data});
        }
      })
    })
  },
	// 获取供求列表
	getSupplyList(num){
		let that = this;
		app.login().then(function(_token){
		  wx.request({
			url: app.baseApiUrl + 'orders/listByIndex',
			data:{limit:num},
			header:{'token': _token},
			success (response){
			  that.setData({needList:response.data.data.need});
			  that.setData({supplyList:response.data.data.supply});
			}
		  })
		})
	},
	// 获取分类列表
	getCategoryList(){
	  let that = this
	  app.login().then(function(_token){
		wx.request({
		  url: app.baseApiUrl + 'Category',
		  header:{'token': _token},
		  success (response){
			that.setData({typeList:response.data.data});
		  }
		})
	  })
	},
	// 获取报价列表
	getQuotedList(num = 5){
		let that = this
		app.login().then(function(_token){
		  wx.request({
			url: app.baseApiUrl + 'Quoted',
			data:{limit:num},
			header:{ 'token': _token},
			success (response){
			  that.setData({produceList:response.data.data});
			}
		  })
		})
		
	},

  
  onLoad:function(){
    this.getBannerList(3);
    this.getSupplyList(4);
	  this.getCategoryList(5);
    this.getQuotedList();

  }
  

})